﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SARUserControls
{
	/// <summary>
	/// SARResultMenuBar.xaml 的交互逻辑
	/// </summary>
	public partial class SARResultMenuBar : UserControl
	{
		public SARResultMenuBar()
		{
			this.InitializeComponent();
            menuItem1.MouseCapture.Opacity = 0.3;
		}

        private int currentSelectedIndex = 0;

        /// <summary>
        /// 获取当前选中的菜单项目，从0开始数
        /// </summary>
        public int SARCurrentSelectedIndex
        {
          get { return currentSelectedIndex; }          
        }
        
        /// <summary>
        /// 菜单被单击了的事件
        /// </summary>
        public event MenuClickHandler SARMenuClick;

        private void menuItem1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            menuItem1.MouseCapture.Opacity = 0.3;
            menuItem2.MouseCapture.Opacity = 0;
            menuItem3.MouseCapture.Opacity = 0;
            menuItem4.MouseCapture.Opacity = 0;
            currentSelectedIndex = 0;
            if (SARMenuClick != null)
            {
                SARMenuClick.Invoke(0);
            }
        }

        private void menuItem2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            menuItem1.MouseCapture.Opacity = 0;
            menuItem2.MouseCapture.Opacity = 0.3;
            menuItem3.MouseCapture.Opacity = 0;
            menuItem4.MouseCapture.Opacity = 0;
            currentSelectedIndex = 1;
            if (SARMenuClick != null)
            {
                SARMenuClick.Invoke(1);
            }
        }

        private void menuItem3_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            menuItem1.MouseCapture.Opacity = 0;
            menuItem2.MouseCapture.Opacity = 0;
            menuItem3.MouseCapture.Opacity = 0.3;
            menuItem4.MouseCapture.Opacity = 0;
            currentSelectedIndex = 2;
            if (SARMenuClick != null)
            {
                SARMenuClick.Invoke(2);
            }
        }

        private void menuItem4_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            menuItem1.MouseCapture.Opacity = 0;
            menuItem2.MouseCapture.Opacity = 0;
            menuItem3.MouseCapture.Opacity = 0;
            menuItem4.MouseCapture.Opacity = 0.3;
            currentSelectedIndex = 3;
            if (SARMenuClick != null)
            {
                SARMenuClick.Invoke(3);
            }
        }

        private void menuItem1_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 0)
            {
                return;
            }
            menuItem1.MouseCapture.Opacity = 0.1;
        }

        private void menuItem1_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 0)
            {
                return;
            }
            menuItem1.MouseCapture.Opacity = 0;
        }

        private void menuItem2_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 1)
            {
                return;
            }
            menuItem2.MouseCapture.Opacity = 0.1;
        }

        private void menuItem2_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 1)
            {
                return;
            }
            menuItem2.MouseCapture.Opacity = 0;
        }

        private void menuItem3_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 2)
            {
                return;
            }
            menuItem3.MouseCapture.Opacity = 0.1;
        }

        private void menuItem3_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 2)
            {
                return;
            }
            menuItem3.MouseCapture.Opacity = 0;
        }

        private void menuItem4_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 3)
            {
                return;
            }
            menuItem4.MouseCapture.Opacity = 0.1;
        }

        private void menuItem4_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentSelectedIndex == 3)
            {
                return;
            }
            menuItem4.MouseCapture.Opacity = 0;
        }        

	}

    public delegate void MenuClickHandler(int menuItemIndex);
}